package com.huatai.vba.properties;

import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class VbaEnv {

	private static final Logger logger = LoggerFactory.getLogger(VbaEnv.class);

	public static boolean isTest = false;

	Properties properties = null;

	@PostConstruct
	public void run() throws Exception {
		String path = this.getClass().getResource("/").getPath();
		if (path.indexOf(".jar") < 0)
			return;
		path = path.substring(0, path.indexOf(".jar"));
		path = path.substring(0, path.lastIndexOf("/") + 1);
		path = path.replace("file:/", "") + "env.properties";
		if (!new File(path).exists())
			return;
		properties = new Properties();
		FileInputStream fis = null;
		try {
			fis = new FileInputStream(path);
			properties.load(fis);
			isTest = "test".equals(properties.get("env"));
		} catch (Exception ex) {
			logger.error("系統異常", ex);
		} finally {
			fis.close();
		}

	}

}
